package com.whmnx.my.ui.base;


import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.databinding.FragmentBasePagerBinding;
import com.whmnx.my.ui.adapter.BaseFragmentPagerAdapter;
import com.whmnx.my.ui.viewmodel.BasePageViewModel;

import java.util.List;

import io.reactivex.annotations.Nullable;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.base.BaseViewModel;

/**
 *
 * @author goldze
 * @date 2017/7/17
 * 抽取的二级BasePagerFragment
 */

public abstract class BasePagerFragment extends BaseFragment<FragmentBasePagerBinding, BaseViewModel> {

    private List<Fragment> mFragments;
    private List<String> titlePager;

    protected abstract List<Fragment> pagerFragment();

    protected abstract List<String> pagerTitleString();

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_base_pager;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }



    @Override
    public void initData() {
        mFragments = pagerFragment();
        titlePager = pagerTitleString();
        //设置Adapter
        BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), mFragments, titlePager);
        binding.viewPager.setAdapter(pagerAdapter);
        binding.tabs.setupWithViewPager(binding.viewPager);
        binding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabs));
        binding.include.tvTitle.setText("神奇播豆");
        binding.include.ivBack.setOnClickListener(v -> viewModel.finish());
    }

    @Override
    public void initViewObservable() {

    }
}
